package com.jmu.account;

import java.util.Date;
import java.util.Scanner;

public class Account {

    protected String id;              //卡号
    protected String name;
    protected int balance;            //余额
    protected double annualRate;      //年利率
    protected Date date;

    //开户 设置 卡号 名字 年利率 开户日期 余额为0
    public Account(String id, String name, double annualRate, Date date) {
        this.id = id;
        this.name = name;
        this.balance = 0;
        this.annualRate = annualRate;
        this.date = date;
    }

    /**
     * 从余额中取款 （不支持透支行为 透支还需要重写)
     * 1: 取款金额 < 余额  -->  取款成功
     * 2: 取款金额 > 余额  -->  取款失败，提示错误，要求重新输入金额  ...
     * @param amount
     */
    public void Withdraw(int amount) {
        //取款金额 < 余额
        if (amount <= this.balance) {
            this.balance -= amount;
            System.out.println("成功取款￥" + amount + " 账户余额￥" + balance);
        } else {
            //取款金额 > 余额
            System.out.println("账户余额不足，仅剩￥" + this.balance + "请重新输入金额");
            Scanner scanner = new Scanner(System.in);
            int newAmount = scanner.nextInt();
            Withdraw(newAmount);
        }
    }

    /**
     * 向余额中存入金额 amount
     * @param amount
     */
    public void Deposit(int amount) {
        this.balance += amount;
        System.out.println("已向余额中存入￥" + amount + " 账户余额￥" + balance);
    }

    //可以用来输出账户信息

    @Override
    public String toString() {
        return "账户信息：" +
                "卡号='" + id + '\'' +
                ", 姓名='" + name + '\'' +
                ", 账户余额=" + balance +
                ", 年利率=" + annualRate +
                ", 开户日期=" + date;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getBalance() {
        return balance;
    }

    public double getAnnualRate() {
        return annualRate;
    }

    public Date getDate() {
        return date;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

    public void setAnnualRate(double annualRate) {
        this.annualRate = annualRate;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}
